<template>
	<view class="container" :class="circle?'circle-container':''">
		<u-navbar v-if="circle == null" title="E萌宠">
			<div slot="left">

			</div>
		</u-navbar>
		<u-navbar v-else title="E萌宠 " bgColor="transparent">
			<div slot="left" class="circle-box">
				<image style="width: 44rpx;height: 44rpx;border-radius: 50%;" :src="circle.avatar" mode=""></image>
				<span>{{circle.name}}</span>
				<image v-if="item.sex == 1" style="width: 36rpx;height: 36rpx;" src="@/static/mine/female.png" mode="">
				</image>
				<image v-else style="width: 36rpx;height: 36rpx;" src="@/static/mine/male.png" mode="">
					<!-- <image style="width: 36rpx;height: 36rpx;" src="../../static/mine/male.png" mode=""></image> -->
			</div>
		</u-navbar>
		<image v-if="circle" class="bg-jb" style="width: 100%;" mode="heightFix" src="../../static/img_jb.png"></image>
		<view class="content-wrap" style="">
			<view class="add-box" v-if="circle == null">
				<image style="width: 100%;" src="../../static/img_add.png" mode="widthFix"></image>
			</view>
			<cu-nav-bar class="cu-nav-bar-box" @clickItem="clickBar" :barList="barList"></cu-nav-bar>

			<view class="content-box">
				<scroll-view class="content-list" :scroll-top="scrollTop" scroll-y="true" @scrolltoupper="upper"
					@scrolltolower="lower" @scroll="scroll">

					<template v-if="list && list.length >0">
						<wContainer :columnNumber="2" v-if="activeBar != 2">
							<wItem v-for="(item, index) in list" :key="index">
								<view class="item">
									<image class="image" style="width: 100%;" :src="item.cover" mode="widthFix"></image>
									<view class="title">{{item.title}}</view>
									<view class="desc">
										<view class="font">
											<image style="width: 40rpx;height: 40rpx;border-radius: 50%;"
												:src="item.user_avatar" mode="">
											</image>
											<span class="name">{{item.nick_name}}</span>
										</view>
										<view class="views">
											<image style="width: 28rpx;height: 28rpx;" src="../../static/icon_show.png"
												mode="">
											</image>
											<span class="browse">{{item.browse}}</span>
										</view>
									</view>
								</view>
							</wItem>
						</wContainer>

						<!-- <custom-waterfalls-flow ref="waterfallsFlowRef" @wapperClick="wapperClick"
							@imageClick="imageClick" @loaded="loaded" :value="list" v-if="activeBar != 2">
							<view class="item" v-for="(item,index) in list" :key="index" slot="slot{{index}}">
								<view class="title">{{item.title}}</view>
								<view class="desc">
									<view class="font">
										<image style="width: 40rpx;height: 40rpx;"
											src="../../static/mine/default_avatar.png" mode=""></image>
										<span>{{item.name}}</span>
									</view>
									<view class="views">
										<image style="width: 28rpx;height: 28rpx;" src="../../static/icon_show.png"
											mode="">
										</image>
										<span>123</span>
									</view>
								</view>
							</view>
						</custom-waterfalls-flow> -->
						<!-- 圈子 -->
						<view v-else>
							<view class="circle-list">
								<view @click="onJumpGroup(item)" class="item-box" v-for="(item,index) in list"
									:key="item">
									<image class="img-avatar" :src="item.cover" mode=""></image>
									<view class="info">
										<view class="name">
											{{item.name}}
										</view>
										<view class="tips">
											{{$Common.timeAgo(item.created_time) }} | {{item.type_id_name}}
										</view>
									</view>
								</view>
							</view>
						</view>
					</template>

					<cu-empty tips="这里没有发现什么~" v-if="list && list.length == 0"></cu-empty>
					<u-loadmore v-else :status="status" />
				</scroll-view>
			</view>
		</view>

		<cu-button-wrap v-if="activeBar == 2">
			<u-button :customStyle="{width:'226rpx',height:'76rpx',borderRadius:'76rpx'}" type="primary" text="新增圈子"
				@click="onAddGroup"></u-button>
		</cu-button-wrap>
	</view>
</template>

<script>
	const iconShow = require('@/static/icon_show.png')
	import wContainer from '@/components/simple-waterfall/w-container.vue'
	import wItem from '@/components/simple-waterfall/w-item.vue'
	import {
		mapState,
		mapActions
	} from 'vuex';
	export default {
		components: {
			wContainer,
			wItem
		},
		data() {
			return {
				iconShow,
				status: 'loadmore',
				scrollTop: 0,
				list: null,
				groupList: null,
				activeBar: 1,
				barList: [{
						label: '关注',
						id: 0
					},
					{
						label: '综合',
						id: 1
					},
					{
						label: '圈子',
						id: 2
					},
					{
						label: '专题',
						id: 3
					},
				],
				circle: null
			}
		},
		computed: {
			...mapState(['userInfo']),
		},
		onShow() {

		},
		onLoad() {
			// this.loadList();
			let _this = this;
			// 更新圈子
			uni.$on('updateGroupList', () => {
				_this.getGroupList();
				_this.activeBar = '2';
			})
			this.load_user_atten_user_post();
			this.getPetList();
		},

		destroyed() {
			uni.$off('updateGroupList')
		},
		methods: {
			// 综合
			load_post_news() {
				this.$Net.get(this.$api.post_news, {
					page: 1,
					limit: 10
				}, 1).then(res => {
					this.list = res.list.map(item => {
						item['image'] = item.cover;
						return item
					});
					this.status = 'nomore';
				})
			},
			// 关注
			load_user_atten_user_post() {
				this.$Net.get(this.$api.user_atten_user_post, {
					page: 1,
					limit: 10
				}, 1).then(res => {
					this.list = res.list.map(item => {
						item['image'] = item.cover;
						return item
					});
					this.status = 'nomore';
				})
			},
			// 专题
			getArticleList() {
				this.$Net.get(this.$api.article_list + "/1", {
					page: 1,
					limit: 10
				}, 1).then(res => {
					this.list = res.list.map(item => {
						item['image'] = item.cover;
						return item
					});
					this.status = 'nomore';
				})
			},
			// 宠物
			getPetList() {
				this.$Net.get(this.$api.pet_List, {
					page: 1,
					limit: 1
				}, 1).then(res => {
					if (res.list && res.list.length > 0) {
						this.circle = res.list[0]
					}
				})
			},
			// 新增圈子
			onAddGroup() {
				this.$Jump.Open('/pages/mine/circle/addCircle')
			},
			// 圈子详情
			onJumpGroup(item) {
				console.log(item);
				this.$Jump.Open('/pages/index/gruop?id=' + item.id)
				// pages/index/gruop
			},
			// 加载圈子列表
			getGroupList() {
				this.status = 'loading';
				this.$Net.get(this.$api.group_list, {
					page: 1,
					limit: 99
				}).then(res => {
					this.status = 'nomore';
					this.list = res.list;
				})
			},
			loaded() {
				console.log('加载完成')
			},
			wapperClick(item) {
				this.$Jump.Open('/pages/index/postDetail')
				console.log('单项点击事件', item)
			},
			imageClick(item) {
				console.log('图片点击事件', item)
				this.$Jump.Open('/pages/index/postDetail')
			},
			reset() {
				this.list = null
				this.$refs.waterfallsFlowRef.refresh();
			},
			// loadList() {
			// 	this.status = 'loading';
			// 	setTimeout(() => {
			// 		if (this.activeBar == 2) {
			// 			this.list = [{
			// 				name: '经检测',
			// 				time: '1小时前',
			// 				cName: '消息'
			// 			}]
			// 			this.status = 'nomore';
			// 			return
			// 		}
			// 		this.list = [{
			// 				image: 'https://fc1tn.baidu.com/it/u=3961765422,3575707746&fm=202&src=781&ernie_sim_online&mola=new&crop=v1',
			// 				title: '我是标题1',
			// 				name: 'xids1'
			// 			},
			// 			{
			// 				image: 'http://my.ichong123.com/files/2019/7/65/2_145714_919496b0be31be1.jpg',
			// 				title: '我是标题2',
			// 				name: 'xids2'
			// 			},
			// 			{
			// 				image: 'https://fc1tn.baidu.com/it/u=3961765422,3575707746&fm=202&src=781&ernie_sim_online&mola=new&crop=v1',
			// 				title: '我是标题3',
			// 				name: 'xids3'
			// 			},
			// 			{
			// 				image: 'http://my.ichong123.com/files/2019/7/65/2_145714_919496b0be31be1.jpg',
			// 				title: '我是标题4',
			// 				name: 'xids4'
			// 			},
			// 			{
			// 				image: 'http://my.ichong123.com/files/2019/7/159/150931mhahcgac9xv18w49.jpg',
			// 				title: '我是标题5',
			// 				name: 'xids5'
			// 			},
			// 			{
			// 				image: 'http://my.ichong123.com/files/2019/7/162/10305273430mjifv1mjifv.jpg',
			// 				title: '我是标题6',
			// 				name: 'xids6'
			// 			},
			// 			{
			// 				image: 'http://my.ichong123.com/files/2019/7/94/092947xtjk7q2zbhmd67ho.jpg',
			// 				title: '我是标题7',
			// 				name: 'xids7'
			// 			}
			// 		]
			// 		// if (this.page >= 3) this.status = 'nomore';
			// 		this.status = 'nomore';
			// 	}, 2000)
			// },
			loaded: function(e) {
				console.log(e)
			},
			upper: function(e) {
				console.log(e)
			},
			lower: function(e) {
				console.log(e)
			},
			scroll: function(e) {
				console.log(e)
				this.scrollTop = e.detail.scrollTop
			},
			loadList() {
				this.list = null;
				if (this.activeBar == 2) {
					this.getGroupList();
				} else if (this.activeBar == 0) {
					this.load_user_atten_user_post();
				} else if (this.activeBar == 1) {
					this.load_post_news();
				} else if (this.activeBar == 3) {
					this.getArticleList();
				}
			},
			clickBar(id) {
				this.activeBar = id;
				this.loadList();
			},
			getList() {
				this.status = 'loading';
				this.$Net.post(this.$api.myClockInfo4Today, {}).then(res => {
					console.log(res)
					if (res.success) {
						this.listAttendance = res.body
						this.status = 'nomore';
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 0;

		::v-deep .btn-box {
			z-index: 99;
		}
	}

	.circle-container {
		::v-deep .u-navbar__content__title {
			color: #fff !important;
		}

		.circle-box {
			min-width: 188rpx;
			height: 64rpx;
			border-radius: 64rpx;
			background: rgba(0, 0, 0, .15);
			display: flex;
			align-items: center;
			padding: 0 10rpx;

			span {
				margin-left: 8rpx;
				margin-right: 6rpx;
				color: rgba(255, 255, 255, 0.90);
				text-align: center;
				font-family: "PingFang SC";
				font-size: 32rpx;
				font-weight: 400;
			}
		}

		.content-wrap {
			border-radius: 40rpx 40rpx 0 0;
			margin-top: 240rpx !important;
		}
	}

	.bg-jb {
		position: absolute;
		top: 0;
		z-index: 2;
	}

	.content-wrap {
		height: calc(100vh - 120px);
		display: flex;
		flex-direction: column;
		padding: 0 32rpx;
		margin-top: 200rpx;
		position: relative;
		z-index: 3;
		background-color: #fff;

		.add-box {
			width: 694rpx;
			// height: 272rpx;
			flex-shrink: 0;
			border-radius: 56rpx;
			background: #68B0FC;
			box-shadow: 0px 42rpx 28rpx -30rpx #C4DDF6;
		}



		.content-box {
			width: 100%;
			flex: 1;
			overflow: auto;

			.content-list {
				flex: 1;
				overflow: auto;

				::v-deep .img {
					border-radius: 28rpx !important;
				}

				.item {
					width: 100%;
					padding-top: 18rpx;
					margin-bottom: 20rpx;

					.image {
						background-color: #C4DDF6;
					}

					.title {
						color: rgba(0, 0, 0, 0.80);
						font-family: "PingFang SC";
						font-size: 30rpx;
						font-weight: 400;
					}

					.desc {
						display: flex;
						align-items: center;
						justify-content: space-between;
						margin-top: 12rpx;
						width: 100%;
						color: rgba(0, 0, 0, 0.50);
						font-family: "PingFang SC";
						font-size: 26rpx;

						.font,
						.views {
							display: flex;
							align-items: center;

							span {
								margin-left: 12rpx;
							}
						}
					}
				}
			}
		}

	}

	.circle-list {
		.item-box {
			margin-bottom: 50rpx;
			border-radius: 16px;
			display: flex;
			align-items: center;

			.img-avatar {
				width: 72rpx;
				height: 72rpx;
				margin-right: 28rpx;
				border-radius: 32rpx;
			}

			.info {
				.name {
					color: #000;
					font-family: "PingFang SC";
					font-size: 36rpx;
					font-weight: 400;
				}

				.tips {
					color: rgba(0, 0, 0, 0.60);
					font-family: "PingFang SC";
					font-size: 28rpx;
					font-weight: 400;
					margin-top: 12rpx;
				}
			}
		}
	}
</style>
